package com.springcloud.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

/**
 * @Author: XiaoJie Wang
 * @Description:
 * @Date: Create in 11:16 2021/7/8
 */
@SpringBootApplication
public class ServiceConsumerApplication {
    public static void main(String[] args) {
        SpringApplication.run(ServiceConsumerApplication.class,args);
    }

    @Bean(name = "restTemplate")
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }

    @Bean(name = "restTemplate01")
    @LoadBalanced  // RestTemplate 时添加 @LoadBalanced 负载均衡注解，表示这个 RestTemplate 在请求时拥有客户端负载均衡的能力。
    public RestTemplate getRestTemplate() {
        return new RestTemplate();
    }

    // 全局设置负载均衡策略
    /*@Bean
    public RandomRule randomRule() {
        return new RandomRule();
    }*/

}
